/*     */ package com.zimbra.cs.mailclient.pop3;
/*     */ 
/*     */ import java.io.EOFException;
/*     */ import java.io.IOException;
/*     */ import java.io.InputStream;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ public final class ContentInputStream
/*     */   extends InputStream
/*     */ {
/*     */   private final InputStream in;
/*     */   private final StringBuilder sbuf;
/*     */   private int pos;
/*     */   
/*     */   public ContentInputStream(InputStream is)
/*     */   {
/*  32 */     this.in = is;
/*  33 */     this.sbuf = new StringBuilder(132);
/*  34 */     this.sbuf.setLength(0);
/*     */   }
/*     */   
/*     */   public int read() throws IOException
/*     */   {
/*  39 */     if (this.pos == -1) return -1;
/*  40 */     if ((this.pos >= this.sbuf.length()) && 
/*  41 */       (!fillBufferWithNextLine())) { return -1;
/*     */     }
/*  43 */     return this.sbuf.charAt(this.pos++);
/*     */   }
/*     */   
/*     */   public String readLine() throws IOException {
/*  47 */     if (this.pos == -1) return null;
/*  48 */     if ((this.pos >= this.sbuf.length()) && 
/*  49 */       (!fillBufferWithNextLine())) { return null;
/*     */     }
/*     */     
/*  52 */     int len = this.sbuf.length() - this.pos;
/*  53 */     String line = len > 2 ? this.sbuf.substring(this.pos, len - 2) : "";
/*  54 */     this.pos = this.sbuf.length();
/*  55 */     return line;
/*     */   }
/*     */   
/*     */   public void close() throws IOException
/*     */   {
/*  60 */     skipRemaining();
/*     */   }
/*     */   
/*     */   private void skipRemaining() throws IOException {
/*  64 */     while (read() != -1) {}
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   private boolean fillBufferWithNextLine()
/*     */     throws IOException
/*     */   {
/*  88 */     this.sbuf.setLength(0);
/*  89 */     int currChar = 0;
/*     */     int prevChar;
/*     */     do {
/*  92 */       prevChar = currChar;
/*  93 */       currChar = this.in.read();
/*  94 */       if (currChar == -1) {
/*  95 */         throw new EOFException("Unexpected end of stream while reading content");
/*     */       }
/*  97 */       this.sbuf.append((char)currChar);
/*  98 */     } while ((currChar != 10) || (prevChar != 13));
/*  99 */     int len = this.sbuf.length();
/*     */     
/* 101 */     if ((len == 3) && (this.sbuf.charAt(0) == '.')) {
/* 102 */       this.pos = -1;
/* 103 */       return false;
/*     */     }
/*     */     
/* 106 */     if ((len >= 4) && (this.sbuf.charAt(0) == '.')) {
/* 107 */       this.sbuf.deleteCharAt(0);
/*     */     }
/* 109 */     this.pos = 0;
/* 110 */     return true;
/*     */   }
/*     */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/cs/mailclient/pop3/ContentInputStream.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */